//
//  Inspection.swift
//  Employee
//
//  Created by swordjoy on 2017/3/23.
//  Copyright © 2017年 remotevillage. All rights reserved.
//

import Foundation
import SwiftyJSON

class Inspection: NSObject, NSCoding {
  
  let recordId: String
  let areaName: String
  let region: String
  let status: String
  let planId: String
  let timeInterval: String
    let cooperate: Bool
  
  init(json: JSON) {
    
    recordId = json["recordId"].stringValue
    areaName = json["areaName"].stringValue
    region = json["regionName"].stringValue
    status = json["status"].stringValue
    planId = json["planId"].stringValue
    timeInterval = json["timeInterval"].stringValue
    cooperate = json["cooperate"].boolValue
    
  }
  
  static func array(from jsonArray: [JSON]) -> [Inspection] {
    return jsonArray.map({ (json) -> Inspection in
      Inspection(json: json)
    })
  }
  
  required init?(coder aDecoder: NSCoder) {
    
    recordId = (aDecoder.decodeObject(forKey: "recordId") as? String) ?? ""
    areaName = (aDecoder.decodeObject(forKey: "areaName") as? String) ?? ""
    region = (aDecoder.decodeObject(forKey: "region") as? String) ?? ""
    status = (aDecoder.decodeObject(forKey: "status") as? String) ?? ""
    planId = (aDecoder.decodeObject(forKey: "planId") as? String) ?? ""
    timeInterval = (aDecoder.decodeObject(forKey: "timeInterval") as? String) ?? ""
    cooperate = (aDecoder.decodeObject(forKey: "cooperate") as? Bool) ?? false
  }
  
  func encode(with aCoder: NSCoder) {
    
    aCoder.encode(recordId, forKey: "recordId")
    aCoder.encode(areaName, forKey: "areaName")
    aCoder.encode(region, forKey: "region")
    aCoder.encode(status, forKey: "status")
    aCoder.encode(planId, forKey: "planId")
    aCoder.encode(timeInterval, forKey: "timeInterval")
    aCoder.encode(cooperate, forKey: "cooperate")
  }
}
